<%--
  Created by IntelliJ IDEA.
  User: Rain
  Date: 2018/9/6
  Time: 14:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>信息管理系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script type="text/javascript" src="/htdc/scripts/jquery/jquery-1.7.1.js"></script>
    <link href="/htdc/style/authority/basic_layout.css" rel="stylesheet" type="text/css">
    <link href="/htdc/style/authority/common_style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/htdc/scripts/authority/commonAll.js"></script>
    <script type="text/javascript" src="/htdc/scripts/jquery/jquery-1.4.4.min.js"></script>
    <script src="/htdc/scripts/My97DatePicker/WdatePicker.js" type="text/javascript" defer="defer"></script>
    <script type="text/javascript" src="/htdc/scripts/artDialog/artDialog.js?skin=default"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            /*
             * 提交
             */
            $("#submitbutton").click(function () {
                var data = $('#submitForm').serialize();
                if (validateForm()) {
                    // checkFyFhSubmit();
                    $.ajax({
                        type: "POST",
                        url: "/htdc/Agreement/addAgreement",
                        data: data,
                        success: function (result) {
                            if (result == 'success') {
                                /**  关闭弹出iframe  **/
                                window.parent.$.fancybox.close();
                            }
                        }

                    })


                    $("#submitbutton").submit(); //提交

                    // parent.$.fancybox.close(); //关闭
                    //
                    // parent.window.location.reload(); //刷新父窗口

                }
            });

            /*
             * 取消
             */
            $("#cancelbutton").click(function () {
                /**  关闭弹出iframe  **/
                window.parent.$.fancybox.close();
            });

            var result = 'null';
            if (result == 'success') {
                /**  关闭弹出iframe  **/
                window.parent.$.fancybox.close();
            }
        });

        /** 检测房源房号是否存在  **/
        function checkFyFh() {
            // 分别获取小区编号、栋号、层号、房号
            var fyID = $('#fyID').val();
            var fyXqCode = $("#fyXq").val();
            var fyDh = $("#fyDh").val();
            var fyCh = $("#fyCh").val();
            var fyFh = $("#fyFh").val();
            if (fyXqCode != "" && fyDh != "" && fyCh != "" && fyFh != "") {
                // 给房屋坐落地址赋值
                $("#fyZldz").val($('#fyDh option:selected').text() + fyCh + "-" + fyFh);
                // 异步判断该房室是否存在，如果已存在，给用户已提示哦
                $.ajax({
                    type: "POST",
                    url: "/htdc/room/changeRoom",
                    data: {
                        "fangyuanEntity.fyID": fyID,
                        "fangyuanEntity.fyXqCode": fyXqCode,
                        "fangyuanEntity.fyDhCode": fyDh,
                        "fangyuanEntity.fyCh": fyCh,
                        "fangyuanEntity.fyFh": fyFh
                    },
                    dataType: "text",
                    success: function (data) {
// 					alert(data);
                        // 如果返回数据不为空，更改“房源信息”
                        if (data == "1") {
                            art.dialog({
                                icon: 'error',
                                title: '友情提示',
                                drag: false,
                                resize: false,
                                content: '该房室在系统中已经存在哦，\n请维护其他房室数据',
                                ok: true,
                            });
                            $("#fyFh").css("background", "#EEE");
                            $("#fyFh").focus();
                            return false;
                        }
                    }
                });
            }
        }

        /** 检测房源房号是否存在并提交form  **/
        function checkFyFhSubmit() {
            // 分别获取小区编号、栋号、层号、房号
            var rid = $('#rid').val();
            var rname = $("#rname").val();
            var roomArea = $("#roomArea").val();
            var roomRealArea = $("#roomRealArea").val();
            if (rid != "" && rname != "" && roomArea != "" && roomRealArea != "") {

                // 异步判断该房室是否存在，如果已存在，给用户已提示哦
                $.ajax({
                    type: "POST",
                    url: "/htdc/room/addRoom",
                    data: {"rid": rid, "rname": rname, "roomArea": roomArea, "roomRealArea": roomRealArea},
                    dataType: "text",
                    success: function (data) {
// 					alert(data);
                        // 如果返回数据不为空，更改“房源信息”
                        // if(data=="1"){
                        //     art.dialog({icon:'error', title:'友情提示', drag:false, resize:false, content:'该房室在系统中已经存在哦，\n请维护其他房室数据', ok:true,});
                        //     $("#fyFh").css("background", "#EEE");
                        //     $("#fyFh").focus();
                        //     return false;
                        // }else{
                        //     $("#submitForm").attr("action", "/htdc/room/changeRoom").submit();
                        // }
                    }
                });
            }
            return true;
        }

        /** 表单验证  **/
        function validateForm() {

            if ($("#roomArea").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写房源产权面积', ok: true,});
                return false;
            }
            if ($("#roomRealArea").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写可出租面积', ok: true,});
                return false;
            }
            if ($("#rname").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写房源名称', ok: true,});
                return false;
            }
            return true;
        }
    </script>
    <style>

        #sider {
            position: absolute;
            top: 0;
            left: 25px;
            bottom: 0px;
            width: 260px;
            border: 1px solid #DEDFDF;
            float: left;
        }

        #main {
            position: absolute;
            top: 0;
            left: 285px;
            right: 0px;
            bottom: 0px;
            border: 1px solid #DEDFDF;
            overflow: auto;
        }

        #box_border {
            border: 1px solid #EDEDED;
            height: 50px;
            line-height: 50px;
            text-align: center;
        }

        #fang_type {
            list-style-type: none;
        }

        #fang_type li {
            width: 80px;
            height: 22px;
            line-height: 22px;
            color: #FFF;
            display: inline-block;
        }

        .fy_table_td {
            color: #fff;
        }

        .fang_th {
            background: #044599 no-repeat;
            text-align: center;
            border-left: 1px solid #02397F;
            border-right: 1px solid #02397F;
            border-bottom: 1px solid #02397F;
            border-top: 1px solid #02397F;
            letter-spacing: 2px;
            text-transform: uppercase;
            font-size: 14px;
            color: #fff;
            height: 37px;
        }


    </style>
</head>
<body>
<form id="submitForm" name="submitForm" action="/htdc/agreement/addAgreement" method="post">
    <div>
        <div id="" style="float: left">
            <table class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
                <tr>
                    <th>选择房间 </th>
                    <th>房间名称</th>
                    <th>产权面积</th>
                    <th>最近租期开始时间</th>
                    <th>最近租期结束时间</th>
            </tr>
                <c:forEach items="${rooms}" var="room">
                    <tr>
                        <td><input type="checkbox" name="rids" value="${room.rid}"> </td>
                        <td>${room.rname}</td>
                        <td>${room.roomArea}</td>
                        <td>${room.rentTime}</td>
                        <td>${room.rentEnd}</td>
                    </tr>
                </c:forEach>

            </table>
        </div>

        <div id="container" style="float: left">
            <div id="nav_links">
                当前位置：基础数据&nbsp;>&nbsp;<span style="color: #1A5CC6;">添加</span>
                <div id="page_close">
                    <a href="javascript:parent.$.fancybox.close();">
                        <img src="/htdc/images/common/page_close.png" width="20" height="20"
                             style="vertical-align: text-top;"/>
                    </a>
                </div>
            </div>
            <div class="ui_content">
                <table cellspacing="0" cellpadding="0" width="100%" align="left" border="0">


                    <tr>
                        <td class="ui_text_rt">合同编号</td>
                        <td class="ui_text_lt">
                            <input type="text" style="width: 200px" id="aid" name="aid" value=""
                                   class="ui_input_txt01"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">起始时间</td>
                        <td class="ui_text_lt">
                            <input type="date" style="width: 200px" id="rentTime" name="rentTime" value=""
                                   class="ui_input_txt01"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">结束时间</td>
                        <td class="ui_text_lt">
                            <input type="date" style="width: 200px" id="rentEnd" name="rentTime" value=""
                                   class="ui_input_txt01"/>㎡
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">收款周期</td>
                        <td class="ui_text_lt">
                            <select style="width: 200px" id="cycle" name="cycle" value="" class="ui_select01">
                                <option value="月">月</option>
                                <option value="季">季</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">租赁方式</td>
                        <td class="ui_text_lt">
                            <select style="width: 200px" id="rentPattern" name="rentPattern" value=""
                                    class="ui_select01">
                                <option value="新租">月</option>
                                <option value="续租">季</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">保证金</td>
                        <td class="ui_text_lt">
                            <input type="text" style="width: 200px" id="rentCash" name="rentCash" value=""
                                   class="ui_input_txt01"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">单价</td>
                        <td class="ui_text_lt">
                            <input type="text" style="width: 200px" id="price" name="price" value=""
                                   class="ui_input_txt01"/>平米
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">免租期</td>
                        <td class="ui_text_lt">
                            <input type="text" style="width: 200px" id="freeTime" name="freeTime" value=""
                                   class="ui_input_txt01"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">递增率</td>
                        <td class="ui_text_lt">
                            <input type="text" style="width: 200px" id="growthRate" name="growthRate" value=""
                                   class="ui_input_txt01"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">承租人</td>
                        <td class="ui_text_lt">
                            <input type="text" style="width: 200px" value="" name="pname" class="ui_input_txt01"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="ui_text_rt">承租人电话</td>
                        <td class="ui_text_lt">
                            <input type="text" style="width: 200px" value="" name="ptel" class="ui_input_txt01"/>
                        </td>
                    </tr>


                    <tr>
                        <td>&nbsp;</td>
                        <td class="ui_text_lt">
                            &nbsp;<input id="submitbutton" type="button" value="提交" class="ui_input_btn01"/>
                            &nbsp;<input id="cancelbutton" type="button" value="取消" class="ui_input_btn01"/>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</form>

</body>
</html>